package com.hrl.web.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LoginFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpSession session = ((HttpServletRequest) servletRequest).getSession();
        Boolean loginState = (Boolean)session.getAttribute("loginState");

        filterChain.doFilter(servletRequest,servletResponse);
        if(!loginState){
            ((HttpServletResponse) servletResponse).sendRedirect("/StdInfoMagSystem_war_exploded/login.html");
        }
    }

    @Override
    public void destroy() {

    }
}
